﻿$(document).on("pageInit", "#create-eva-stu", function (e, id, page) {
    var $CourceId = $(page).find('[name="CourceId"]');

    loadCourceList();

    function loadCourceList() {
        $.getJSON("/Evaluate/GetCourceList4Student", {}, function (response) {
            $CourceId.empty();
            if (response.length > 0) {
                $.each(response, function (rIndex, rItem) {
                    $CourceId.append("<option value='" + rItem.CourceId + "'>" + rItem.CourceName + "</option>");
                });
                loadTeacherList(response[0].CourceId);
            }
        });
    }
    $CourceId.change(function () {
        loadTeacherList($CourceId.val());
    });
    function loadTeacherList(courceId) {
        $.getJSON("/Evaluate/GetTeacherListByCourceId", { courceId: courceId }, function (response) {
            var $TeacherUserId = $(page).find('[name="TeacherUserId"]');
            $TeacherUserId.empty();
            if (response.length > 0) {
                $.each(response, function (rIndex, rItem) {
                    $TeacherUserId.append("<option value='" + rItem.Id + "'>" + rItem.RealName + "</option>");
                });
            }
        });
    }

    $(page).find("[name=create-eva-student-form]").on("submit", function (evt) {
        evt.preventDefault();
        $(page).find("[name=create-eva-student-form]").ajaxSubmit({
            success: function (response) {
                if (response.indexOf("err:") > -1) {
                    $.toast(response.substr(4));
                    return false;
                }
                history.back();
            }
        });
    });
});